package aor2.cpu.blockinterface;

import aor2.components.Element;
import aor2.components.Register;
import aor2.components.Signal;
import aor2.cpu.InternBus;
import aor2.cpu.blockcontrol.ControlSignalSet;

/**
 * MBR registar
 * 
 * @author Moxi
 * 
 */
final public class Mbr extends Register {

	Mbr() {
		super();
		m2mbrout = ControlSignalSet.getInstance().get("M2MBRout");
	}

	Mbr(long state, Element input, Element output) {
		super(state, input, output);
		m2mbrout = ControlSignalSet.getInstance().get("M2MBRout");
	}

	private Signal m2mbrout;

	@Override
	public void in() {
		super.setState(InternBus.M1.getState());
	}

	@Override
	public void out() {
		if (m2mbrout.isActive()) {
			out2();
		} else {
			out1();
		}
	}

	private void out1() {
		InternBus.M1.setState(state);
	}

	private void out2() {
		InternBus.M2.setState(state);
	}

	@Override
	public String toString() {
		return "MBR: " + state;
	}
}
